<template>
  <el-dialog
    title="新增"
    :close-on-click-modal="false"
    :visible.sync="visible"
    @close="closeDialog"
    width="80%"
    top="8vh"
  >
    <el-row>
      <el-form
        :model="addForm"
        :rules="dataRule"
        ref="addForm"
        @keyup.enter.native="dataFormSubmit()"
        label-width="130px"
      >
        <div class="mbcjbg">
          <el-row>
            <el-col :span="24">
              <el-col :span="12">
                <el-form-item label="模板名称" prop="mbname">
                  <el-input
                    v-model="addForm.mbname"
                    placeholder="模板名称"
                    :clearable="true"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="描述" prop="description">
                  <el-input
                    v-model="addForm.description"
                    placeholder="描述"
                    :clearable="true"
                  ></el-input>

                </el-form-item>

              </el-col>
            </el-col>
          </el-row>
        </div>
      </el-form>

    </el-row>
    <ZhuanXiangGzForm ref="zxgzRef" :zhuanxiangGzForm="addForm"></ZhuanXiangGzForm>
    <!--  选择人员信息-->

    <span slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        plain
        @click="saveFormData"
        v-loading.fullscreen.lock="fullscreenLoading"
        >保存</el-button
      >
      <el-button type="primary" plain @click="closeDialog">关闭</el-button>
    </span>
  </el-dialog>
</template>
<script>
import {
    saveZxgzFaQi,
} from "@/api/hetongrenwu/zhuanxianggongzuo/zxgzmbcj";
import ZhuanXiangGzForm from "@/views/hetongrenwu/zxgz/zxgzmbcj/mbcj/zhuanxianggz-form.vue";
import { effective } from "@/api/hetongrenwu/hetongyeji/hetongnd";

export default {
  components: {
    ZhuanXiangGzForm,
  },
  props: {
    addDataForm: {
    },
  },
  data() {
    return {
      visible: false,
      categoryList: [],
      dataForm: {},
      addForm:{},
      jsonData: "",
      zhuanxiangGzForm: {},
      dataRule: {
          mbname: [
          { required: true, message: "请输入模板名称", trigger: "change" },
        ],
          description: [
          { required: true, message: "请输入描述", trigger: "change" },
        ]
      },
      fullscreenLoading: false,
      zdrwBkhUsers: [],
    };
  },
  watch: {},
  created() {
    this.fneffective();
  },
  methods: {
    //关闭清空任务数据
    closeDialog() {
      this.$refs.zxgzRef.dataList = [];
        this.$emit("refreash", "closeDialog");
        this.visible = false;

    },
    //初始化
    csh() {
      //this.addForm = this.addDataForm
        console.log(this.addDataForm.mbname);

      //this.shouyuerenNameList = "";

    },
    init(data) {
      this.csh();
      this.visible = true;

      if (data != undefined) {
        //this.dataForm = data;
        this.$forceUpdate();
      }
    },
    changeValue(value){
      console.log(value)
      if(value == 1){
        this.$refs.zxgzRef.dataList = [];
      }
    },
    change(e){
        this.$forceUpdate();
    },
      saveFormData() {
      //整理被考核人信息
        /*this.dataForm.zdrwBkhUsers = this.zdrwBkhUsers;

      if (this.shouyuerendataList == 0) {
         this.$message.warning("请选择被考核人");
         return;
       }*/

      //新增分数设置数字验证
      this.addForm.zxgzPfmbSubs = this.$refs.zxgzRef.dataList;
        const szValid = /^[0-9]*$/
        let flag=true;
        this.addForm.zxgzPfmbSubs.forEach((ele) => {

            if(ele.fssz != null || ele.fssz !=""){

                if (!szValid.test(ele.fssz)) {
                    this.$message.warning("分数设置请输入数字");
                    flag=false;
                    return;
                }

            }
        });
      if(flag){
          this.$refs["addForm"].validate((valid) => {
              if (valid) {
                  this.fullscreenLoading = true;
                  saveZxgzFaQi(this.addForm).then((res) => {
                      this.$message.closeAll();
                      this.$message.success("保存成功");
                      this.visible = false;
                      this.$emit("refreshDataList");
                      this.fullscreenLoading = false;
                  });
              } else {
                  return false;
              }
          });
      }

    },
    addUser(type) {
      this.jsonData = JSON.stringify(this.shouyuerendataList);
      this.$nextTick(() => {
        this.$refs.usercomment.init("12", type, this.jsonData, "htcj");
      });
    },
    submitfy(data) {
      //this.shouyuerendataList = [];
      this.zdrwBkhUsers = [];
      this.shouyuerendataList = data.tableDataUser;
      this.shouyuerendataList.forEach((ele) => {
        var user = {};
        user.userId = ele.userId;
        user.userName = ele.userCode;
        user.ryName = ele.userName;
        user.deptId = ele.deptId;
        user.userDeptName = ele.deptName;
        user.userZw = ele.userZw;
        user.userLx = "总部发起";
        user.userZj = ele.userZj;
        this.zdrwBkhUsers.push(user);
      });
      console.log(this.shouyuerendataList);
      console.log(this.zdrwBkhUsers);
    },
    //打开指标维护
    fnOpenZhibiao() {
      var param = {
        openZhi: true,
      };
      this.$emit("openZhibiao", param);
    },
    // 获取下拉
    fneffective() {
      effective({
        tagName: "专项工作",
      }).then((res) => {
        this.categoryList = res.data.data;
      });
    },
  },
};
</script>
<style scoped>
.mbcjbg {
  border-radius: 16px;
  -webkit-box-shadow: 5px 5px 10px #e3e3ea, -5px -5px 10px #ffffff;
  box-shadow: 5px 5px 10px #e3e3ea, -5px -5px 10px #ffffff;
  background: #fbfbfd;
  padding: 10px 30px 30px 30px;
}
</style>
